package com.xxq.semester.service.impl.exam;

import com.xxq.semester.entity.exam.ExamResources;
import com.xxq.semester.mapper.ExamResourcesMapper;
import com.xxq.semester.service.exam.IExamResourcesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author saki
 * @since 2025-07-13
 */
@Service
public class ExamResourcesServiceImpl extends ServiceImpl<ExamResourcesMapper, ExamResources> implements IExamResourcesService {

    @Override
    public List<ExamResources> listAll() {
        return this.list();
    }

    @Override
    public void saveSelectedResources(Long examId, List<Long> resourceIds) {
        if (examId == null || resourceIds == null || resourceIds.isEmpty()) return;
        List<ExamResources> list = resourceIds.stream()
            .map(rid -> {
                ExamResources er = new ExamResources();
                er.setExamId(examId.intValue());
                er.setResourceId(rid.intValue());
                return er;
            })
            .toList();
        this.saveBatch(list);
    }
}
